//
//  CollectionTitleCell.m
//  sensen_ios
//
//  Created by mc on 16/3/4.
//  Copyright © 2016年 pro. All rights reserved.
//

#import "CollectionTitleCell.h"

@implementation CollectionTitleCell

+(instancetype)cellWithTableView:(UITableView*)tableView{
    
    static NSString * cellIdentifier = @"CollectionTitleCell";
    CollectionTitleCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell ==nil) {
        cell = [[self alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    return cell;
    
}

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self =  [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSeparatorStyleNone;
       
        
    }
    return self;
}
- (void)setupSubViews{
    
    for (UIView *view in self.contentView.subviews) {
        [view removeFromSuperview];
    }
    if (_isHaveBtn) {
        self.selectButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.contentView addSubview:self.selectButton];
        [self.selectButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.contentView.mas_centerY);
            make.left.equalTo(self.contentView).offset(10);
            make.size.mas_equalTo(CGSizeMake(20, 20));
        }];
        
        [_selectButton setBackgroundImage:[UIImage imageNamed:@"购物车_未选中"] forState:UIControlStateNormal];
        [_selectButton setBackgroundImage:[UIImage imageNamed:@"购物车_选中"] forState:UIControlStateSelected];
        
        // 头像
        self.iconImgView = [[UIImageView alloc] init];
        _iconImgView.image = [UIImage imageNamed:@"person_message_disabled"];
        _iconImgView.clipsToBounds = YES;
        [self.contentView addSubview:_iconImgView];
        [self.iconImgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.contentView.mas_centerY);
            make.left.equalTo(self.selectButton.mas_right).offset(5);
            make.size.mas_equalTo(CGSizeMake(35, 35));
        }];

    }else{
        // 头像
        self.iconImgView = [[UIImageView alloc] init];
        _iconImgView.image = [UIImage imageNamed:@"person_message_disabled"];
        _iconImgView.clipsToBounds = YES;
        [self.contentView addSubview:_iconImgView];
        [self.iconImgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.contentView.mas_centerY);
            make.left.equalTo(self.contentView).offset(10);
            make.size.mas_equalTo(CGSizeMake(35, 35));
        }];
        

    }
    
    
    
    
    
    // 昵称
    self.nickLabel = [[UILabel alloc] init];
    _nickLabel.font = B_FONT(15);
    _nickLabel.text = @"发帖人昵称";
    _nickLabel.textColor = rgba(12, 91, 158, 1);
    _nickLabel.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:_nickLabel];
    [_nickLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconImgView.mas_right).offset(5);
        make.size.mas_equalTo(CGSizeMake(230, 18));
        make.top.equalTo(self.iconImgView.mas_top).offset(0);
    }];
    
    // 发表时间
    self.createTimeLabel = [[UILabel alloc] init];
    _createTimeLabel.font = FONT(13);
    _createTimeLabel.text = @"2016-3-1 10:10:10";
    _createTimeLabel.textColor = [UIColor lightGrayColor];
    _createTimeLabel.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:_createTimeLabel];
    [_createTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nickLabel.mas_left).offset(0);
        make.size.mas_equalTo(CGSizeMake(230, 15));
        make.bottom.equalTo(self.iconImgView.mas_bottom).offset(0);
    }];

}

- (void)setIsHaveBtn:(BOOL)isHaveBtn{
    _isHaveBtn = isHaveBtn;
    [self setupSubViews];
}

- (void)setModel:(CollectionModel *)model{
    
    _model = model;
    [_iconImgView setImageURLStr:model.authorImage placeholder:DEFAULT_IMAGE];
    // 设置头像圆角
    _iconImgView.layer.cornerRadius = 15;
    _iconImgView.layer.masksToBounds = YES;
    
    _createTimeLabel.text = [NSDate getDateStringFromeNumber:[NSNumber numberWithInteger:[model.create_time integerValue]]];
    if (model.nickname.length == 0) {
        _nickLabel.text = model.author;
    }else{
        _nickLabel.text = model.nickname;
    }
    
    
}


@end
